package com.boot.mgt.service.impl

import com.boot.core.result.MsgBean
import com.boot.core.result.ResultTo
import com.boot.core.util.ActivemqManager
import com.boot.mgt.dao.mysql.TaSysConfigMapper
import com.boot.mgt.model.TaSysConfig
import com.boot.mgt.service.TaSysConfigService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.stereotype.Service

/**
 * @author kawins
 * createTime 2019-03-18 21:29
 */
@Service
class TaSysConfigServiceImpl : TaSysConfigService {


    @Autowired
    private lateinit var taSysConfigMapper: TaSysConfigMapper

    @Autowired
    private lateinit var activemqManager: ActivemqManager


    override fun update(sysConfig: TaSysConfig) {
        taSysConfigMapper.updateByPrimaryKeySelective(sysConfig)
        sysConfig.reportSwitch?.apply {
            if (this) {
                MsgBean().let {
                    it.msgType = 2
                    activemqManager.send(it)
                }
            }
        }
    }

    override fun selectAll(): ResultTo {
        return ResultTo().setData("data", taSysConfigMapper.selectAll())
    }
}